--以我铸规
local yiwozhugui = fk.CreateSkill {
    name = "mcdh_yiwozhugui",
    tags ={Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

yiwozhugui:addEffect(fk.Death,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self,false,true) and player == target
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local tar = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 2,2, "#mcdh_yiwozhugui", self.name, false)
        local sort = table.filter(room:getAlivePlayers(),function(p) return table.contains(tar,p.id) end)
        local choices = {"yiwozhugui1","yiwozhugui2"}
        if sort[2].dead then
            table.removeOne(choices,"yiwozhugui1")
        end
        local card = sort[1]:getCardIds("he")
        if #table.filter(card,function(id) return not sort[1]:prohibitDiscard(Fk:getCardById(id) )and Fk:getCardById(id).type ~= Card.TypeBasic  end) < 2 then
            table.removeOne(choices,"yiwozhugui2")
        end
        if #choices > 0 then
            local choice = room:askForChoice(sort[1], choices, self.name, nil, nil,{"yiwozhugui1","yiwozhugui2"})
            if choice == "yiwozhugui1" then
                room:damage({
                    from = sort[1],
                    to = sort[2],
                    damage = 1,
                    skillName = self.name,
                })
            else
                room:askForDiscard(player, 2, 2, true, self.name, false, ".|.|.|.|.|^basic", "#yiwozhugui-discard")
            end
        end
        if not sort[2].dead then
            local choices = {"yiwozhugui1","yiwozhugui2"}
            if sort[1].dead then
                table.removeOne(choices,"yiwozhugui1")
            end
            local card = sort[2]:getCardIds("he")
            if #table.filter(card,function(id) return not sort[2]:prohibitDiscard(Fk:getCardById(id) )and Fk:getCardById(id).type ~= Card.TypeBasic  end) < 2 then
                table.removeOne(choices,"yiwozhugui2")
            end
            if #choices > 0 then
                local choice = room:askForChoice(sort[2], choices, self.name, nil, nil,{"yiwozhugui1","yiwozhugui2"})
                if choice == "yiwozhugui1" then
                    room:damage({
                        from = sort[2],
                        to = sort[1],
                        damage = 1,
                        skillName = self.name,
                    })
                else
                    room:askForDiscard(sort[1], 2, 2, true, self.name, false, ".|.|.|.|.|^basic", "#jiaoxueyuanyuan-discard")
                end
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_yiwozhugui"] = "以我铸规",
    [":mcdh_yiwozhugui"] = "锁定技，当你死亡时，你选择两名其他角色，这些角色依次选择一项：1.对另一名角色造成1点伤害；2.弃置两张非基本牌。",
    ["yiwozhugui1"] = "1.对另一名角色造成1点伤害",
    ["yiwozhugui2"] = "2.弃置两张非基本牌",
    ["#yiwozhugui-discard"] = "以我铸规:弃置两张非基本牌",
}

return yiwozhugui